home *** CD-ROM | disk | FTP | other *** search
- /*
- * MenusLib Interface.c
- *
- * calls PPC routines in "MenusLib Stub.c"
- *
- * You ask why do we need that Stub?
- * Well, for a PPC-only plugin, one could include the MenusLib
- * and call the functions directly. However, that would require
- * the MenusLib to be present even when it is not needed. Mac OS
- * before 8.5 does not have the Lib installed and so you'd be
- * getting an error when loading the plugin (and your app would
- * kind of crash). By using this dynamically loadable stub,
- * we decide whether we want to access the MenusLib at all and
- * will make the plugin work with all OS versions.
- * And, for a 68K plugin, there's no Trap provided for calling
- * the new Menu Mgr functions, so we need this stub in order to
- * switch into PowerPC mode and then call the functions.
- *
- * Updated 3 May, 99 for v1.1:
- * Fixed code so that it can also call the PPC stub if this code runs in PPC mode, too.
- *
- * Updated 6 May, 99 for v1.1.1:
- * Added DetachResource() call in getStub() so that built apps will not crash any more.
- */
-
- #include <MixedMode.h>
- #include "MenusLib Stub.h"
- #include "MenusLib Interface.h"
-
-
- static far MenusLibFuncs funcs = {0};
-
- static far Boolean stubOK;
-
- static MenusLibStubProc getStub ()
- {
- Handle resource;
- resource = Get1Resource ('MLib', 128);
- if (!resource) return nil;
- DetachResource (resource); // v1.1.1 - this is important or we'll get crashes in built apps
- HLockHi (resource);
- return (MenusLibStubProc)*resource;
- }
-
- pascal void MenusLibShowMenuBar (void)
- {
- if (stubOK) {
- #if TARGET_RT_MAC_CFM
- CALL_ZERO_PARAMETER_UPP((UniversalProcPtr)funcs.showMenuBar, kPascalStackBased);
- #else
- funcs.showMenuBar();
- #endif
- }
- }
-
- pascal void MenusLibHideMenuBar (void)
- {
- if (stubOK) {
- #if TARGET_RT_MAC_CFM
- CALL_ZERO_PARAMETER_UPP((UniversalProcPtr)funcs.hideMenuBar, kPascalStackBased);
- #else
- funcs.hideMenuBar();
- #endif
- }
- }
-
- pascal Boolean MenusLibIsMenuBarVisible (void)
- {
- if (stubOK) {
- #if TARGET_RT_MAC_CFM
- return CALL_ZERO_PARAMETER_UPP((UniversalProcPtr)funcs.isMenuBarVisible, kPascalStackBased|RESULT_SIZE(SIZE_CODE(sizeof(Boolean))));
- #else
- return funcs.isMenuBarVisible();
- #endif
- } else {
- return false;
- }
- }
-
- Boolean InitMenusLibInterface ()
- {
- MenusLibStubProc initMenusLibStub = getStub();
- stubOK = initMenusLibStub != nil;
- if (stubOK) {
- #if TARGET_RT_MAC_CFM
- CALL_ONE_PARAMETER_UPP((UniversalProcPtr)initMenusLibStub, MenusStubInitProcInfo, &funcs);
- #else
- initMenusLibStub (&funcs);
- #endif
- }
- return stubOK;
- }
-
- // EOF
-